package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.OrderSettingDao;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ：zboy
 * @date ：
 * @description ：
 * @version: 1.0
 */
@Slf4j
@Service
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    public void add(List<OrderSetting> list) {
        if(list == null || list.size() == 0){
            log.debug("list is null");
            throw new RuntimeException("数据不能为空");
        }
        //批量添加
        for (OrderSetting orderSetting:list){
            //检查此数据（日期）是否存在
            long count = orderSettingDao.countByOrderDate(orderSetting.getOrderDate());
            if (count > 0){
                //已经存在，执行更新操作
                orderSettingDao.updateOrderSettingByOrderDate(orderSetting);
            }else{
                //不存在，执行添加操作
                orderSettingDao.add(orderSetting);
            }
        }
    }
}
